var catId = getUrlParam('catId');
var pcatId = getUrlParam('pcatId');
var page = getUrlParam('page');
var rows = getUrlParam('rows');

function init() {
    $.ajax({

        type: "post",
        url: ajaxUrl + "/mobile/collect/collects",
        async: true,
        data: {'memberId': memberId},
        success: function (data) {
            console.log(data);
            var result = data.result;
            var str="";
            for (var i=0;i<result.length;i++) {
                str += '<div class="list2-item bottom-border">' +
                    '			<a href="details.html?id='+result[i].productId+'" class="text-img">' +
                    '				<div class="img-wrapper">' +
                    '					<img src="'+result[i].image+'" alt="" class="img">' +
                  //  '					<img src="img/qiang-tag.png" alt="" class="tag">' +
                    '				</div>' +
                    '				<div class="text">' +
                    '					<div class="text-top">' +
                    '						<div class="name">'+result[i].productName+'</div>' +
                    '						<div class="sell">销量'+result[i].saleCount+'</div>' +
                    '					</div>' +
                   // '					<div class="old-price">市价¥32.00</div>' +
                    '					<div class="now-price">售价:￥<i>'+result[i].price+'</i></div>' +
                    '				</div>' +
                    '			</a>' +
                    '			<div class="add-cart-wrapper">' +
                    '				<div onclick="shanchu('+result[i].productId+')"  class="add-cart delet"></div>' +
                    '			</div>' +
                    '		</div>';
            }

            $("#lista").html(str);
        }
    });
}


function shanchu(id) {



        $.ajax({

            type: "post",
            url: ajaxUrl + "/mobile/collect/delete",
            async: true,
            data: {'memberId': memberId,"objIds":id},
            success: function (data) {
                init();
            }
        });
}

//选择商品
function selectProduct(id) {

}
//选择分类
function selectCategoryId(id) {
    console.log(id);
     window.location.href ='more.html?catId='+catId+'&pcatId='+id;
}
function productList() {
    if (page == null || page == 0) {
        page = 1;
        rows = 100;
    }
    $.ajax({
        type: "post",
        url: ajaxUrl + "/mobile/product/productList",
        async: true,
        data: {'catId': pcatId, 'memberId': memberId, 'sort': 1, 'page': page, 'rows': rows},
        success: function (data) {
            console.log(data);
            var result = data.result;
            var htmlStr = "";
            for (var i=0;i<result.length;i++) {
                htmlStr += '	<div class="list2-item bottom-border">' +
                    '			<a href="details.html?id='+result[i].productId+'" class="text-img">' +
                    '				<div class="img-wrapper">' +
                    '					<img src="' + result[i].image + '" alt="" class="img">' +
                    //    '					<img src="img/qiang-tag.png" alt="" class="tag">' +
                    '				</div>' +
                    '				<div class="text">' +
                    '					<div class="text-top">' +
                    '						<div class="name">' + result[i].productName + '</div>' +
                    '						<div class="sell">销量' + result[i].saleCount + '</div>' +
                    '					</div>' +
                    '					<div class="now-price">会员价:￥<i>' + result[i].vipPrice + '</i></div>' +
                    '				</div>' +
                    '			</a>' +
                    '			<div class="add-cart-wrapper">' +
                    '				<div class="add-cart" onclick="addCart('+memberId+','+result[i].productId+','+null+','+1+')"></div>' +
                    '			</div>' +
                    '		</div>';
            }
            $('#list2').html(htmlStr);
        }
    });

}

//添加到购物车
 function addCart(memberId, productId, normalId, num) {
        $.ajax({
            type: "post",
            url: ajaxUrl + '/mobile/carItem/addProduct',
            async: true,
            //productId=412&memberId=623&normalId=508&num=1
            data: {'memberId': memberId, 'productId': productId, 'normalId': normalId, 'num': num},
            success: function (data) {
                if (data.code == 0) {
                    alertMsg('成功加入购物车');
                } else {
                    alertMsg(data.message);
                }
                $('.spec-section').removeClass('on');
                $('.mask').hide();
                 cartNum();
            },
            error: function () {
                errorTip();
            },
            complete: function () {

            }
        });
    }

function showRight(children) {
    var rightStr = "";
    for (var i = 0; i < children.length; i++) {
        rightStr += '<a href="more.html?catId=' + children[i].id + '" class="content-item">';
        rightStr += '<img src="' + children[i].logo + '" alt="" class="icon">';
        rightStr += '<div class="text">' + children[i].name + '</div></a>';
    }

    $('#rightList').html(rightStr);
}